package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

class BottomBackgroundView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : SurfaceViewTemplate(context, attributeSet) {

    private val mPaint by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            style = Paint.Style.FILL
            color = context.resources.getColor(R.color.color_E60C3F)
        }
    }

    private val mPath by lazy {
        Path()
    }

    init {
        mHolder.addCallback(this)
    }

    override fun Canvas.onDrawContent() {
        val cx = mWidth.toFloat()
        val cy = mHeight.toFloat()

        drawColor(context.resources.getColor(R.color.color_F3F3F3))

        mPath.apply {
            moveTo(0F, cy / 10)
            lineTo(cx * 7 / 25, cy / 10)
            quadTo(
                cx / 2,
                -cy / 10,
                cx * 18 / 25,
                cy / 10
            )
            lineTo(cx, cy / 10)
            lineTo(cx, cy)
            lineTo(0F, cy)
            close()
        }

        drawPath(mPath, mPaint)
    }
}